package com.ripservice.controller;

import com.ripcore.engine.SimulationConfig;
import com.ripservice.service.SimulationService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 仿真配置控制器
 * 提供RESTful API接口用于获取和设置特定仿真的配置参数
 */
@RestController
@RequestMapping("/api/simulations/{simulationId}/config")
@RequiredArgsConstructor
public class SimulationConfigController {

    /**
     * 仿真服务实例，用于处理仿真相关的业务逻辑
     */
    private final SimulationService simulationService;

    /**
     * 获取指定仿真的配置信息
     *
     * @param simulationId 仿真ID
     * @return 包含仿真配置的ResponseEntity对象
     */
    @GetMapping
    public ResponseEntity<SimulationConfig> getConfig(@PathVariable("simulationId") String simulationId) {
        SimulationConfig cfg = simulationService.getSimulationConfig(simulationId);
        return ResponseEntity.ok(cfg);
    }

    /**
     * 设置指定仿真的配置信息
     *
     * @param simulationId 仿真ID
     * @param config       新的仿真配置对象
     * @return 表示操作成功的ResponseEntity对象
     */
    @PutMapping
    public ResponseEntity<Void> setConfig(@PathVariable("simulationId") String simulationId, @RequestBody SimulationConfig config) {
        simulationService.setSimulationConfig(simulationId, config);
        return ResponseEntity.ok().build();
    }
}